cc.Class({
    extends: cc.Component,

    properties: {
       storyString: {
            type: cc.RichText,
            default: null
       },
	   
	   jump: {
            type: cc.Label,
            default: null
       },
    },


     onLoad () {
		 
		 this.story = "某天,皇上一家子被魔王抓到了魔塔，一时间，朝野震惊。大臣们商议后，决定派出作为大内第一高手的你，去拯救他们.....".split("");
		 
		 //console.log(this.story);
		 
		 this.index = 0;
		 
		 this.storyrealstring = "";
		 
		 this.storyString.string = "";
		 
		 this.calindex = 0;
		 
		 this.calmax = 5;
		 
		 this.stop = 0;
		 
		 this.jump.node.on(cc.Node.EventType.TOUCH_END, function(){
			 this.stop=1;
			 this.jump.active = false;
			 this.node.runAction(cc.sequence(cc.delayTime(0.1),cc.callFunc(function(){
				 cc.director.loadScene('helloworld');
			 },this)));
		 }, this); 
	 },

	update (dt) {
				
		if(this.stop==0){
			
			//console.log("telling ... ");
			
			if(this.calindex<this.calmax){
				this.calindex++;
			}else{
				this.calindex = 0;
			
				if(this.index<this.story.length){
					this.storyrealstring+= this.story[this.index];
					this.storyString.string = this.storyrealstring;
					this.index++;
				}else{
					this.stop = 1;
				}
			}
		}else{
			cc.director.loadScene('helloworld');
		}
				
	},
});
